package org.oep.widgets;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import org.oep.widgets.Widget;

public class TextWidget extends Widget {
	private int color;
	private Font font;
	private String text;
	private int lifetime = 1;

	public TextWidget(int x, int y, String s, int c, Font f) {
		this.x = x;
		this.y = y;
		this.text = s;
		this.color = c;
		this.font = f;
		this.lifetime = 1;
	}
	
	public void paint(Graphics g, int x, int y) {
		paint(g,x,y,Graphics.HCENTER | Graphics.BOTTOM);
	}
	
	public void paint(Graphics g, int x, int y, int mode) {
		if(font == null || text == null || lifetime <= 0) return;
		
		int c = g.getColor();
		Font f = g.getFont();
		
		g.setFont(font);
		g.setColor(color);

		g.drawString(text, x, y, mode);
		
		g.setFont(f);
		g.setColor(c);
	}
	
	public int getWidth() {
		if(text == null || font == null) return 0;
		return font.charsWidth(text.toCharArray(), 0, text.length());
	}
	
	public int getHeight() {
		if(text == null || font == null) return 0;
		return font.getHeight();
	}
	
	public void setFont(Font f) {
		this.font = f;
	}
	
	public void setColor(int c) {
		this.color = c;
	}
	
	public void setText(String s) {
		this.text = s;
	}
	
	public void setLife(int i) {
		lifetime = i;
	}
	
	public int getLife() {
		return lifetime;
	}

	public Font getFont() {
		return font;
	}

}
